using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Health : MonoBehaviour
{
    public int HP;
    public bool isPlayer;

    private void Start()
    {
        if (this.tag == "Player")
        {
            HP = 2;
            isPlayer = true;
        }
        else
        {
            HP = 1;
            isPlayer = false;
        }
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.layer == 6 || collision.gameObject.tag == "bullet" || collision.gameObject.name == "bullet")
        {
            HP -= 1;
            if (HP <= 0)
            {
                Dead();
            }
        }
    }

    public void Dead()
    {
        if (isPlayer)
        {
            this.GetComponent<PlayerMove>().enabled = false;
            this.GetComponent<Rigidbody2D>().velocity = Vector2.zero;
            return;
        }
        else
        {
            this.GetComponent<EnemyMovement>().enabled=false;
            this.GetComponent<EnemySight>().enabled=false;
            this.GetComponent<EnemyStateMachine>().enabled=false;
            this.GetComponent<EnemyCombat>().enabled=false;
            this.tag = "Body";
        }
    }
}
